﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using QuanLyHocPhi.Entity;
using QuanLyHocPhi.DAL;
using QuanLyHocPhi.Util;
namespace QuanLyHocPhi
{
    public partial class frmMucphi : DevComponents.DotNetBar.Metro.MetroForm
    {
        MUC_PHI_DAO mpDao = new MUC_PHI_DAO();
        MUC_PHI mp = new MUC_PHI();
        DOI_TUONG dt = new DOI_TUONG();
        
        public int MaDoiTuong { get; set; }
        public frmMucphi(int maDoiTuong)
        {
            InitializeComponent();
            this.MaDoiTuong = maDoiTuong;
        }




         
         IList<MUC_PHI> ds = null;
        private void frmMucphi_Load(object sender, EventArgs e)
        {
            
            dataGridViewX1.AutoGenerateColumns = false;
           ds = mpDao.SelectByObjectId(MaDoiTuong);
           dataGridViewX1.DataSource = ds;
           
            
        }

        
        private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            mp = mpDao.GetFeeLevelById(MaDoiTuong);
            //mp.SO_LAN_THANH_TOAN = txtSolantt.Text.ToString().ToString();
            
            txtSolantt.Text = mp.SO_LAN_THANH_TOAN.ToString(); 
            txtSolantt.Text = ds[e.RowIndex].SO_LAN_THANH_TOAN.ToString(); 
            txtTongtien.Text = ds[e.RowIndex].TONG_TIEN.ToString(); 

            
            txtThoihan.Text = ds[e.RowIndex].THOI_HAN.ToString();
            mp = ds[e.RowIndex];

           

           
           
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            int err = 0;
            if (txtTongtien.Text == "")
            {
                errorProvider.SetError(txtTongtien, "Yêu cầu nhập tổng tiền");
            }
            mp.SO_LAN_THANH_TOAN = KieuDuLieu.ChuyenSangsonguyen(txtSolantt.Text.ToString(), out err);
            mp.TONG_TIEN = KieuDuLieu.Chuyensangsothuc(txtTongtien.Text.ToString(), out err);
            mp.THOI_HAN = KieuDuLieu.ChuyenSangsonguyen(txtThoihan.Text.ToString(), out err);
            mp.DOI_TUONG = new DOI_TUONG() {MA_DOI_TUONG = MaDoiTuong };
            mpDao.Insert(mp);
            frmMucphi_Load(sender, e);
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            int err = 0;
            mp.SO_LAN_THANH_TOAN = KieuDuLieu.ChuyenSangsonguyen(txtSolantt.Text.ToString(), out err);
            mp.TONG_TIEN = KieuDuLieu.Chuyensangsothuc(txtTongtien.Text.ToString(), out err);
            mp.THOI_HAN = KieuDuLieu.ChuyenSangsonguyen(txtThoihan.Text.ToString(), out err);
            mp.DOI_TUONG = new DOI_TUONG() { MA_DOI_TUONG = MaDoiTuong };
            mpDao.Update(mp);
            frmMucphi_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            mpDao.Delete(mp.MA_MUC_PHI);
            MessageBox.Show("Xóa thành công", "Thông báo");
            txtSolantt.Text = "";
            txtTongtien.Text = "";
            txtTongtien.Text = "";
            frmMucphi_Load(sender, e);
        }

        

        
    }
}